import cv2
from shoot_util import exist_img, find_max_num, get_hms


class ShootCamera(object):
    def __init__(self,path):
        print('准备打开摄像头')
        self.video=cv2.VideoCapture(path,cv2.CAP_DSHOW)#微软特有cv2.CAP_DSHOW
        print('已打开摄像头')

    def __del__(self):
        self.video.release()
        print('已销毁当前帧')

    def get_frame(self):
        success,image=self.video.read()
        print('返回当前帧')
        return image

def save_img(camera,count):
    print('执行save_img函数')
    num=int(find_max_num())
    print('num:',num)
    if count<num:
        count=num

    print('count:',count)
    #while shoot_flag:
    count+=1
    img=camera.get_frame()#frame
    img_path,flag= exist_img(count)
    print('img_path:',img_path)
    if not flag:
        cv2.imwrite(img_path,img)
#
#     return img_path,count

def save_img2(camera):
    print('执行save_img2函数')
    count=get_hms()
    print('count:',count)
    #while shoot_flag:
    img=camera.get_frame()#frame
    img_path,flag= exist_img(count)
    print('img_path:',img_path)
    cv2.imwrite(img_path,img)

    return img_path

if __name__=='__main__':
    save_img(ShootCamera(0),0)
